{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "graffitiCellId": "id_h83uq5h"
   },
   "source": [
    "## References\n",
    "\n",
    "As mentioned previously, a reference is another name given to an existing variable. On the left hand side of any variable declaration, the `&` operator can be used to declare a reference. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "graffitiCellId": "id_tjh2m8z",
    "graffitiConfig": {
     "executeCellViaGraffiti": "id_3q19eh4_cklt1kl"
    }
   },
   "outputs": [],
   "source": [
    "#include <iostream>\n",
    "using std::cout;\n",
    "\n",
    "int main() \n",
    "{\n",
    "    int i = 1;\n",
    "    \n",
    "    // Declare a reference to i.\n",
    "    int& j = i;\n",
    "    cout << \"The value of j is: \" << j << \"\\n\";\n",
    "    \n",
    "    // Change the value of i.\n",
    "    i = 5;\n",
    "    cout << \"The value of i is changed to: \" << i << \"\\n\";\n",
    "    cout << \"The value of j is now: \" << j << \"\\n\";\n",
    "    \n",
    "    // Change the value of the reference.\n",
    "    // Since reference is just another name for the variable,\n",
    "    // th\n",
    "    j = 7;\n",
    "    cout << \"The value of j is now: \" << j << \"\\n\";\n",
    "    cout << \"The value of i is changed to: \" << i << \"\\n\";\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "graffitiCellId": "id_3q19eh4"
   },
   "source": [
    "<span class=\"graffiti-highlight graffiti-id_3q19eh4-id_cklt1kl\"><i></i><button>Compile & Execute</button></span> &nbsp; <span class=\"graffiti-highlight graffiti-id_e1euv0z-id_ot156mu\"><i></i><button>Explain</button></span>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "graffitiCellId": "id_05lniic",
    "graffitiConfig": {
     "rows": 10,
     "terminalId": "id_ka7dleu",
     "type": "terminal"
    }
   },
   "source": [
    "<i>Loading terminal (id_05lniic), please wait...</i>"
   ]
  }
 ],
 "metadata": {
  "graffiti": {
   "firstAuthorId": "813558546",
   "id": "id_lbbhkgw",
   "language": "EN"
  },
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xeus-cling-cpp17"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "-std=c++17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
